﻿using System;
using System.Windows.Forms;

namespace Map_Creator.MainForm
{
    public partial class TreeViewControl : UserControl
    {
        public TreeViewControl()
        {
            InitializeComponent();
            MapInfo.Map.SelectedLayerChanged += Map_SelectedLayerChanged;
            OpacitySlider.Enabled = false;
        }

        void Map_SelectedLayerChanged(MapInfo.Map map)
        {
            if (map != null && map.CurrentLayer != null)
            {
                OpacitySlider.Enabled = true;
                OpacitySlider.Value = map.CurrentLayer.opacity;
            }
            else
                OpacitySlider.Enabled = false;
        }

        private void OnSliderValueChanged(object sender, EventArgs e)
        {
            OpacityLabel.Text = "Opacity: " + OpacitySlider.Value + "%";
            MapInfo.Map.SelectedMap.CurrentLayer.opacity = OpacitySlider.Value;
            
            // Force Refresh
            MapInfo.Map.SelectedMap.CurrentLayer = MapInfo.Map.SelectedMap.CurrentLayer;
        }
    }
}
